package com.xiaobu.shop.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.xiaobu.shop.chatgpt.OpenAiApi;
import com.xiaobu.shop.domain.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/shop/chat")
public class ShopChatGptController {
    @Autowired
    private OpenAiApi openAiApi;

    @RequestMapping("/question")
    public ResponseResult openAiChat(@RequestBody String question){
        if(StringUtils.isBlank(question)){
            ResponseResult responseResult=new ResponseResult(300,"请输入消息");
            return responseResult;
        }
        ResponseResult chat = openAiApi.createChatCompletion(question);
        return chat;
    }
}
